package co.edu;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
//import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
//import android.view.View;
//import android.view.View.OnClickListener;
//import android.widget.Button;

public class actEstadistica extends Activity {

	TextView modulo, correctas, incorrectas, resultado;
	Button btnRegresar;
	Datos con = new Datos(this,"SaberPro",null,1);
	
	 @Override
	    public void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        setContentView(R.layout.estadistica);	        
	       
	        TextView modulo = (TextView)findViewById(R.id.EsttxtModulo);
	        TextView correctas = (TextView)findViewById(R.id.EsttxtCorrectas);
	        TextView incorrectas = (TextView)findViewById(R.id.EsttxtEquivocadas);
	        TextView resultado = (TextView)findViewById(R.id.EsttxtResultado);
	        Button btnRegresar = (Button)findViewById(R.id.EstRegresar);
	        
	        SQLiteDatabase db = con.getReadableDatabase();
	        
	        Cursor c = db.rawQuery("SELECT DISTINCT(m.nom_mod), r.usr_rta,  r.clv_prg FROM respuestas AS r " +
	        		"INNER JOIN modulos as m ON r.mod_prg = m.id_mod", null);
	        
	        if (c.moveToFirst()){
	        	
	        	modulo.setText(c.getString(0));
	        	
	        	int contar = 0;
	        	
	        	do {
	        		
	        		if (c.getString(1).contentEquals(c.getString(2))){
	        			
	        			contar++;
	        			
	        		}
	        		
	        	}
	        	while (c.moveToNext());
	        	
	        	correctas.setText(contar);
	        	incorrectas.setText((c.getCount()-contar));
	        	
	        	resultado.setText("Resultado " + ((contar/c.getCount())*100)+ "%");
	        	
	        	c.close();
	        }
	        
	        btnRegresar.setOnClickListener(new OnClickListener() {
				
				public void onClick(View v) {
					// TODO Auto-generated method stub
					startActivity(new Intent("co.edu.inicio"));
					finish();
					
				}
			});
	 }
}
